import axios from './axios-config';

// 检查账号是否存在
export function checkAccountByPost(data){
  const res = axios.post('/Login/checkAccount',data);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
        if(result.status===200){
          return result.data;
        }else{
          reject(result.status)
        }
      })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}

// 检查密码是否存在
export function chackPasswordByPost(data){
  const res = axios.post('/Login/chackPassword',data);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}
// 根据账号密码进行登录
export function loginByPost(data){
  const res = axios.post('/Login/login',data);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}
// 根据时间和名字创建班级信息
export function createClassByPost(data){
  const res = axios.post('/ClassManager/create',data);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}
// 获取班级列表
export function getClassListByGet(){
  const res = axios.get('/ClassManager/getClassList');
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}

// 删除级列信息
export function deleteClassByGet(id){
  const res = axios.get('/ClassManager/deleteClass?id='+id);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}

// 获取宿舍列表
export function getDormitoryListByGet(){
  const res = axios.get('/DormitoryManager/getDormitoryList');
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}

// 创建宿舍信息
export function createDormitoryByPost(data){
  const res = axios.post('/DormitoryManager/createDormitory',data);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}

// 删除宿舍信息
export function deleteDormitoryByGet(id){
  const res = axios.get('/DormitoryManager/deleteDormitory?id='+id);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}
// 修改宿舍信息
export function changeDormitoryByPost(data){
  const res = axios.post('/DormitoryManager/changeDormitory',data);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}

// 获取分组列表
export function getGroupListByGet(){
  const res = axios.get('/GroupManager/getGroupList');
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}


// 创建分组信息
export function createGroupByPost(data){
  const res = axios.post('/GroupManager/createGroup',data);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}

// 删除分组信息
export function deleteGroupByGet(id){
  const res = axios.get('/GroupManager/deleteGroup?id='+id);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}

// 修改分组信息
export function changeGroupByPost(data){
  const res = axios.post('/GroupManager/changeGroup',data);
  return new Promise((resolve,reject)=>{
    res.then((result)=>{
      console.log("result", result)
      if(result.status===200){
        return result.data;
      }else{
        reject(result.status)
      }
    })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}




// 检查账号是否存在: 废弃示例
export function chackAccountByGet(userAccount){
  const res = axios.get('/Login/chackAccount?userAccount='+userAccount);
  return new Promise((resolve,reject)=>{
    res
      .then((result)=>{
        if(result.status===200){
          return result.data;
        }else{
          reject(result.status)
        }
      })
      .then((json)=>{
        resolve(json);
      })
      .catch((e)=>{
        reject(e.toString())
      })
  })
}
